package com.liuceng.zen.service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.liuceng.zen.mapper.RptFrontCampaignDailyMapper;
import com.liuceng.zen.pojo.domain.RptFrontCampaignDaily;

@Service
public class RptFrontCampaignService {
  @Autowired
  RptFrontCampaignDailyMapper rptFrontCampaignDailyMapper;


  public Map<String, Object> findPcData(Integer memberId) {
    Map<String, Object> params = new HashMap<>();
    params.put("memberId", memberId);
    params.put("sitesetType", RptFrontCampaignDaily.SITESET_TYPE_PC);
    ///
    return rptFrontCampaignDailyMapper.findRptData(params);
  }

  public Map<String, Object> findMobileData(Integer memberId) {
    Map<String, Object> params = new HashMap<>();
    params.put("memberId", memberId);
    params.put("sitesetType", RptFrontCampaignDaily.SITESET_TYPE_MOBILE);
    ///
    return rptFrontCampaignDailyMapper.findRptData(params);
  }

  public BigDecimal findPcCost(Integer memberId) {
    Map<String, Object> data = findPcData(memberId);
    if (data == null || data.get("total_cost") == null)
      return new BigDecimal(0);
    return (BigDecimal) data.get("total_cost");
  }

  public BigDecimal findMobileCost(Integer memberId) {
    Map<String, Object> data = findMobileData(memberId);
    if (data == null || data.get("total_cost") == null)
      return new BigDecimal(0);
    return (BigDecimal) data.get("total_cost");
  }

  public int findPcPv(Integer memberId) {
    Map<String, Object> data = findPcData(memberId);
    if (data == null)
      return 0;
    return Integer.parseInt(data.get("pv") == null ? "0" : data.get("pv").toString());
  }

  public int findPcPc(Integer memberId) {
    Map<String, Object> data = findPcData(memberId);
    if (data == null)
      return 0;
    return Integer.parseInt(data.get("pc") == null ? "0" : data.get("pc").toString());
  }

  public int findMobilePv(Integer memberId) {
    Map<String, Object> data = findMobileData(memberId);
    if (data == null)
      return 0;
    return Integer.parseInt(data.get("pv") == null ? "0" : data.get("pv").toString());
  }

  public int findMobilePc(Integer memberId) {
    Map<String, Object> data = findMobileData(memberId);
    if (data == null)
      return 0;
    return Integer.parseInt(data.get("pc") == null ? "0" : data.get("pc").toString());
  }
}
